package com.durian.base.rxhttp.download

import com.durian.base.rxhttp.param.IRxHttp

/**
 * 说明：RangeHeader
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2021/10/20 10:13 下午
 * <p/>
 * 版本：version 1.0
 */
interface RangeHeader {
    fun setRangeHeader(startIndex: Long, endIndex: Long, connectLastProgress: Boolean): IRxHttp
}

internal fun IRxHttp.setRangeHeader(
    osFactory: OutputStreamFactory<*>,
    append: Boolean
) {
    var offsetSize = 0L
    if (append && this is RangeHeader && osFactory.offsetSize().also { offsetSize = it } >= 0) {
        setRangeHeader(offsetSize, -1, true)
    }
}